import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import  WindiCSS  from "vite-plugin-windicss"  // <==
import Icons from 'unplugin-icons/vite'
import IconsResolver from 'unplugin-icons/resolver'
import { resolve } from 'path'

// https://vitejs.dev/config/

export default defineConfig({
  server: {
    host:'0.0.0.0',
    port: 5137,
    open:true,
    https:false,
    cors:true,
    proxy:{
      '/api': {
        secure: false, // 请求是否为https
        changeOrigin: true, // 是否跨域
        target:'http://127.0.0.1:9000/',
        ws:false,
        rewrite: (path) => path.replace(/^\/api/, '') // 接口以abc开头开始,真正的接口是不需要api的
      }
    }
  },
  plugins: [
      vue(),
    WindiCSS(),
    AutoImport({

      // dts: 'src/auto-imports.d.ts', // 可以自定义文件生成的位置，默认是根目录下
      imports: ['vue',"vue-router"],
      // Auto import functions from Element Plus, e.g. ElMessage, ElMessageBox... (with style)
      // 自动导入 Element Plus 相关函数，如：ElMessage, ElMessageBox... (带样式)
      resolvers: [
        ElementPlusResolver(),

        // Auto import icon components
        // 自动导入图标组件
        IconsResolver({
          prefix: "Icon",
        }),
      ],
    }),
    Components({
      //resolvers: [ElementPlusResolver()] // 这里就是相关ui库的解析工具, 里面的选项有是否使用自动导入样式 如果需要通过 var 变量改变主题 需要注意一下
      resolvers: [
        // Auto register icon components
        // 自动注册图标组件
        IconsResolver({
          enabledCollections: ["ep"],
        }),
        // Auto register Element Plus components
        ElementPlusResolver(),
      ],
    }),
    // 图标
    Icons({
      autoInstall: true,
    }),

  ],
  resolve: {
    alias: {
      '@': resolve(__dirname, 'src'),
    }
  }




})